package com.my.vote.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.my.vote.entity.VoteOption;

public interface VoteOptionRepository extends JpaRepository<VoteOption, String> {

	@Query(value = " select o from VoteOption o where o.delFlag = 0 and o.questionId =?1 order by o.orderNum asc ")
	List<VoteOption> findAllByQuestionId(String questionId);

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query(value = " update VoteOption o set o.delFlag = 1 where o.delFlag = 0 and o.questionId =?1 ")
	void deleteAllByQuestionId(String questionId);

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query(value = " update VoteOption o set o.delFlag = 1 where o.delFlag = 0 and o.id =?1 ")
	void deleteById(String id);
}
